#ifndef __ARMOR_RECOGNITION_H__
#define __ARMOR_RECOGNITION_H__

#include <iostream>
#include <opencv2/core/utility.hpp>
#include <opencv2/videoio.hpp>
#include <opencv2/highgui.hpp>
#include <pthread.h>
#include "opencv2/videoio.hpp"
#include <cmath>
#include <opencv2/ml/ml.hpp> 
#include <fstream>
#include <stdio.h>
#include "debug.h"

using namespace cv;
using namespace std;
using namespace cv::ml;


typedef struct
{
	RotatedRect rect;
	float max_led_height;
	int num;
}my_rect;


class ArmorRecognition
{
public:

	//在构造函数中读取或初始化参数
	ArmorRecognition(FileStorage fsRead);

	//识别装甲板的主要函数
	int TrackArmor(Mat frame, Ptr<SVM> svm,  Ptr<SVM> sentry, Rect RoiRect, Mat src, int id);

	//调整灯条和装甲板的角度（角度范围：-90°~90°）
	bool Suitble(RotatedRect &r1, RotatedRect &r2);

	//框出装甲板并将roi坐标变为原来坐标
	void DrawBox(RotatedRect &box, Mat img, Rect RoiRect);

	//获取装甲板中数字区域，然后进行分类
	int GetNum(RotatedRect box, Ptr<SVM> svm, Mat frame);

	//获取候选装甲板
	vector<my_rect> ArmorDetect(vector<RotatedRect> vEllipse, Mat frame, Ptr<SVM> svm, Ptr<SVM> sentry, int id);

	//模式标志位（是否找到装甲板、小陀螺模式、哨兵模式）
	bool Isfind, Mode, Sentry;

	//区分红蓝场参数与阈值参数
	int color_of_enemy;
	int color_th_, gray_th_;

	//最终装甲板的角度距离信息
	double yaw_;
	double pitch_;
	float distance_;
	float angle_;

	//最终装甲板的位置信息
	float height_, width_, x_, y_;

#ifdef DEBUG
public:
#else
private:
#endif
	//识别时的条件限制参数
	int min_area_, max_area_;
	int min_length_, max_length_;
	int min_led_ratio_, max_led_ratio_;
	int min_armor_ratio_, max_armor_ratio_;
	int diff_angle_;
private:

	//输出识别进度
	ofstream outfile;

	//已获取样本数量
	int sample_count_;

	//用于对装甲板高进行滤波
	vector<float> vheight;

	//用于在多装甲板中寻找之前出现次数最多的装甲板号码
	vector<int> vnum;

};

#endif

